home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AnswerShell.c
-
- Contains: shell for MoreOpenAndSaveDemo
-
- Written by: Pete Gontier
-
- Copyright: Copyright (c) 1997-1998 Apple Computer, Inc.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
-
- <4> 7/27/98 PCG remove warnings re: missing params because Quinn treats warnings
- as errors
- <3> 7/24/98 PCG remove #include "MoveableModalDialog.h"
- <2> 7/11/98 PCG add header
- */
-
-
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #include "MoreOpenAndSave.h"
- #include "MoreDialogs.h"
-
- #include <Fonts.h>
- #include <Sound.h>
-
- enum
- {
- kResID_Base = 128,
- kResID_DialogItemList_CustomGetFile = kResID_Base,
- kResID_DialogItemList_CustomPutFile
- };
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static pascal Boolean CustomFileFilterProc (CInfoPBPtr cipbp, void *)
- {
- Boolean dropIt = false;
-
- if (!(cipbp->hFileInfo.ioFlAttrib & ioDirMask))
- if (cipbp->hFileInfo.ioFlFndrInfo.fdCreator != 'CWIE')
- dropIt = true;
-
- return dropIt;
- }
-
- static pascal Boolean StandardFileFilterProc (CInfoPBPtr cipbp)
- {
- Boolean dropIt = false;
-
- //
- // File filters for StandardGetFile should never be asked
- // to filter directories. We test here for that problem.
- //
-
- if (cipbp->hFileInfo.ioFlAttrib & ioDirMask)
- DebugStr ("\pI was told there'd be no math.");
- else if (cipbp->hFileInfo.ioFlFndrInfo.fdCreator != 'CWIE')
- dropIt = true;
-
- return dropIt;
- }
-
- static pascal Boolean ModalFilterYDProc
- (DialogPtr /* dialog */, EventRecord * /* event */, short * /* itemHit */, void * /* yourDataPtr */)
- {
- SysBeep (-1);
- return false;
- }
-
- static pascal OSErr MyStandardGetFile (void)
- {
- OSErr err = noErr;
-
- FileFilterUPP upp = NewFileFilterProc (StandardFileFilterProc);
-
- if (!upp)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
-
- err = MOASI_StandardGetFile (upp,1,sft,&sfr);
-
- DisposeRoutineDescriptor (upp);
-
- if (!err && sfr.sfGood)
- {
- err = FSMakeFSSpec (sfr.sfFile.vRefNum, sfr.sfFile.parID, sfr.sfFile.name, &(sfr.sfFile));
- }
- }
-
- return err;
- }
-
- static pascal OSErr MyStandardOpenDialog (void)
- {
- StandardFileReply reply;
-
- return MOASI_StandardOpenDialog (&reply);
- }
-
- static pascal OSErr MyStandardPutFile (void)
- {
- StandardFileReply reply;
-
- return MOASI_StandardPutFile ("\pPrompt","\pDefaultFileName",&reply);
- }
-
- static pascal OSErr MyCustomGetFile (void)
- {
- OSErr err = noErr;
-
- FileFilterYDUPP fileFilterUPP = NewFileFilterYDProc (CustomFileFilterProc);
-
- if (!fileFilterUPP)
- err = MemError ( );
- else
- {
- ModalFilterYDUPP eventFilterUPP = NewModalFilterYDProc (ModalFilterYDProc);
-
- if (!eventFilterUPP)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
- void *context = nil;
-
- err = MOASI_CustomGetFile (fileFilterUPP,1,sft,&sfr,kResID_DialogItemList_CustomGetFile,nil,eventFilterUPP,context);
-
- DisposeRoutineDescriptor (eventFilterUPP);
- }
-
- DisposeRoutineDescriptor (fileFilterUPP);
- }
-
- return err;
- }
-
- static pascal OSErr MyCustomPutFile (void)
- {
- OSErr err = noErr;
-
- StandardFileReply reply;
- ModalFilterYDUPP filterProcUPP = nil;
- void *context = nil;
-
- err = MOASI_CustomPutFile ("\pPrompt","\pDefaultFileName",&reply,kResID_DialogItemList_CustomPutFile,nil,filterProcUPP,context);
-
- return err;
- }
-
- static pascal Boolean ModalFilterProc (DialogRef dialog, EventRecord *event, short *itemHit)
- {
- return StdFilterProc (dialog,event,itemHit);
- }
-
- void main (void)
- {
- if (InitMac ( ))
- SysBeep (-1);
- else
- {
- DialogRef dlgRef = GetNewDialog (129,nil,(WindowRef)-1);
- if (dlgRef)
- {
- ModalFilterUPP modalFilterUPP = NewModalFilterProc (ModalFilterProc);
- if (modalFilterUPP)
- {
- enum
- {
- kDialogItemIndex_PushButton_Quit = kStdOkItemIndex,
- kDialogItemIndex_PushButton_StandardGetFile,
- kDialogItemIndex_PushButton_StandardPutFile,
- kDialogItemIndex_PushButton_StandardOpenFile,
- kDialogItemIndex_PushButton_CustomPutFile,
- kDialogItemIndex_PushButton_CustomGetFile
- };
-
- short itemHit;
-
- SetDialogDefaultItem (dlgRef,kDialogItemIndex_PushButton_Quit);
- SetDialogTracksCursor (dlgRef,true);
-
- do
- {
- OSErr err = noErr;
-
- MoveableModalDialog (modalFilterUPP,&itemHit);
-
- switch (itemHit)
- {
- case kDialogItemIndex_PushButton_StandardGetFile :
-
- err = MyStandardGetFile ( );
- break;
-
- case kDialogItemIndex_PushButton_StandardPutFile :
-
- err = MyStandardPutFile ( );
- break;
-
- case kDialogItemIndex_PushButton_StandardOpenFile :
-
- err = MyStandardOpenDialog ( );
- break;
-
- case kDialogItemIndex_PushButton_CustomGetFile :
-
- err = MyCustomGetFile ( );
- break;
-
- case kDialogItemIndex_PushButton_CustomPutFile :
-
- err = MyCustomPutFile ( );
- break;
- }
-
- if (err) SysBeep (-1);
- }
- while (itemHit != kDialogItemIndex_PushButton_Quit);
-
- DisposeRoutineDescriptor (modalFilterUPP);
- }
- DisposeDialog (dlgRef);
- }
- }
- }
-